package com.cencat.order.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 订单统计VO
 * 
 * @author cencat
 * @since 2024
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "订单统计信息")
public class OrderStatsVO {
    
    @Schema(description = "总订单数")
    private Long totalOrders;
    
    @Schema(description = "今日订单数")
    private Long todayOrders;
    
    @Schema(description = "本周订单数")
    private Long weekOrders;
    
    @Schema(description = "本月订单数")
    private Long monthOrders;
    
    @Schema(description = "总订单金额")
    private BigDecimal totalAmount;
    
    @Schema(description = "今日订单金额")
    private BigDecimal todayAmount;
    
    @Schema(description = "本周订单金额")
    private BigDecimal weekAmount;
    
    @Schema(description = "本月订单金额")
    private BigDecimal monthAmount;
    
    @Schema(description = "待支付订单数")
    private Long pendingPaymentOrders;
    
    @Schema(description = "待发货订单数")
    private Long pendingShipmentOrders;
    
    @Schema(description = "待收货订单数")
    private Long pendingReceiptOrders;
    
    @Schema(description = "已完成订单数")
    private Long completedOrders;
    
    @Schema(description = "已取消订单数")
    private Long cancelledOrders;
    
    @Schema(description = "退款订单数")
    private Long refundOrders;
    
    @Schema(description = "订单完成率（百分比）")
    private BigDecimal completionRate;
    
    @Schema(description = "订单取消率（百分比）")
    private BigDecimal cancellationRate;
    
    @Schema(description = "平均订单金额")
    private BigDecimal averageOrderAmount;
    
    @Schema(description = "最高订单金额")
    private BigDecimal maxOrderAmount;
    
    @Schema(description = "最低订单金额")
    private BigDecimal minOrderAmount;
    
    @Schema(description = "每日订单趋势")
    private List<DailyOrderTrend> dailyTrends;
    
    @Schema(description = "订单状态分布")
    private List<OrderStatusDistribution> statusDistribution;
    
    @Schema(description = "热门商品排行")
    private List<PopularProduct> popularProducts;
    
    @Schema(description = "用户订单排行")
    private List<UserOrderRanking> userRankings;
    
    /**
     * 每日订单趋势
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "每日订单趋势")
    public static class DailyOrderTrend {
        
        @Schema(description = "日期")
        private LocalDate date;
        
        @Schema(description = "订单数量")
        private Long orderCount;
        
        @Schema(description = "订单金额")
        private BigDecimal orderAmount;
        
        @Schema(description = "新用户数")
        private Long newUserCount;
    }
    
    /**
     * 订单状态分布
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "订单状态分布")
    public static class OrderStatusDistribution {
        
        @Schema(description = "订单状态")
        private Integer status;
        
        @Schema(description = "状态名称")
        private String statusName;
        
        @Schema(description = "订单数量")
        private Long orderCount;
        
        @Schema(description = "占比（百分比）")
        private BigDecimal percentage;
    }
    
    /**
     * 热门商品排行
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "热门商品排行")
    public static class PopularProduct {
        
        @Schema(description = "商品ID")
        private Long productId;
        
        @Schema(description = "商品名称")
        private String productName;
        
        @Schema(description = "商品图片")
        private String productImage;
        
        @Schema(description = "销售数量")
        private Long salesCount;
        
        @Schema(description = "销售金额")
        private BigDecimal salesAmount;
        
        @Schema(description = "排名")
        private Integer ranking;
    }
    
    /**
     * 用户订单排行
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "用户订单排行")
    public static class UserOrderRanking {
        
        @Schema(description = "用户ID")
        private Long userId;
        
        @Schema(description = "用户名称")
        private String userName;
        
        @Schema(description = "用户头像")
        private String userAvatar;
        
        @Schema(description = "订单数量")
        private Long orderCount;
        
        @Schema(description = "消费金额")
        private BigDecimal totalAmount;
        
        @Schema(description = "排名")
        private Integer ranking;
    }
}